home *** CD-ROM | disk | FTP | other *** search
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- #include "shared.fx"
- #include "lighting.fx"
- #include "fog.fx"
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- //------------------------------------------------------------------------------------------------------
- //- Static parameters
- //------------------------------------------------------------------------------------------------------
-
- texture DiffuseMap;
- texture NormalMap;
- texture GlossinessMap;
- texture SpecularMap;
- shared float Time; // a float that ranges up from 0.0f to 1.0f cycling for time-based effects
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- struct CVertexShaderInput
- {
- float4 Position : POSITION;
- float3 Normal : NORMAL;
- float2 DiffuseUv : TEXCOORD0;
- float3 BumpTangent : TEXCOORD1;
- float3 BumpNormal : TEXCOORD2;
- };
-
- //------------------------------------------------------------------------------------------------------
-
- struct CVertexShaderOutput
- {
- float4 Position : POSITION;
- float2 DiffuseUv : TEXCOORD0;
- float2 NormalUv : TEXCOORD1;
- float3 TextureSpaceLightVector1 : COLOR0;
- float3 TextureSpaceLightVector2 : COLOR1;
- FOG_OPTION_VERTEX_FIELD
- };
-
- //------------------------------------------------------------------------------------------------------
-
- struct CVertexShaderOutputTech2
- {
- float4 Position : POSITION;
- float2 DiffuseUv : TEXCOORD0;
- float3 DiffuseColor : COLOR0;
- FOG_OPTION_VERTEX_FIELD
- };
-
- //------------------------------------------------------------------------------------------------------
-
- struct CVertexShaderOutputSpec
- {
- float4 Position : POSITION;
- float2 DiffuseUv : TEXCOORD0;
- float2 NormalUv : TEXCOORD1;
- float3 TextureSpaceLightVector : TEXCOORD2;
- float3 TextureSpaceLightVectorHalf : TEXCOORD3;
- float3 SpecularStrength : COLOR0;
- FOG_OPTION_VERTEX_FIELD_HACK(COLOR1)
- };
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- // ambient + 2 omnis + bump + specular (2 passes : diffuse + specular)
-
- CVertexShaderOutput OpaBumpLitGeomTech1Pass1 (const CVertexShaderInput input);
- CVertexShaderOutputSpec OpaBumpLitGeomTech1Pass2 (const CVertexShaderInput input);
- CVertexShaderOutputTech2 OpaBumpLitGeomTech2 (const CVertexShaderInput input);
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- #define DISPLACEMENT_FACTOR_TANGENT 5.0f
- #define DISPLACEMENT_FACTOR_NORMAL 1.0f
- #define MY_2_PI 6.28318531f
- #define PHASE 1.0f
-
- /*
- float4 AddNoise(const float4 vPositionToNoise)
- {
- float rSinTime = 1.0f + sin(MY_2_PI * PHASE * Time);
- rSinTime /= 2.0f;
- float4 ToBeReturned = vPositionToNoise;
- ToBeReturned *= (1.0f + rSinTime);
- ToBeReturned.w = vPositionToNoise.w;
-
- return ToBeReturned;
- }
- float rCosTime = cos(MY_2_PI * PHASE * Time);
- float rSinTime = abs(sin(MY_2_PI * PHASE * Time));
-
- // add a random component based on actual position...
- float4 ToBeReturned = vPositionToNoise;
- ToBeReturned.xyz += rVertexRandom * rCosTime * vTangent * DISPLACEMENT_FACTOR_TANGENT;
- ToBeReturned.xyz += rVertexRandom * rSinTime * vNormal * DISPLACEMENT_FACTOR_NORMAL;
- return ToBeReturned;
- */
-
-
- CVertexShaderOutput OpaBumpLitGeomTech1Pass1 (const CVertexShaderInput input)
- {
- CVertexShaderOutput output;
-
- // output position into world+view+projection space
- output.Position = mul (input.Position,WorldCameraProjection);
-
- // binormal computation based on input tangent and normal in local space
- //float3 binormal = ComputeBinormal (input.BumpTangent,input.BumpNormal,input.Normal);
- float3 binormal = input.Normal;
-
- float3 omniDirectionTextureSpace[2];
-
- for (int i=0;i<2;i++)
- {
- // omnilight direction computation
- float4 omniDirection = ComputeVectorAndLength (ObjectLocalLightPosition[i],input.Position);
-
- // omnilight direction to texture space
- omniDirectionTextureSpace[i] = TextureSpaceTransform (omniDirection.xyz,input.BumpTangent,input.BumpNormal,binormal);
- omniDirectionTextureSpace[i] *= ComputeAttenuation (omniDirection.w,LightAttenuationFarStart[i],LightAttenuationFarEnd[i],LightAttenuationDelta[i]);
- }
-
- // omnilight 1 output to diffuse
- output.TextureSpaceLightVector1.xyz = omniDirectionTextureSpace[0] * 0.5f + 0.5f;
-
- // omnilight 2 output to diffuse
- output.TextureSpaceLightVector2.xyz = omniDirectionTextureSpace[1] * 0.5f + 0.5f;
-
- // Diffuse Uv output
- output.DiffuseUv = input.DiffuseUv;
-
- // Normal Uv output
- output.NormalUv = input.DiffuseUv;
-
- // fog computation
- FOG_OPTION_COMPUTE(output, output.Position);
-
- return output;
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- CVertexShaderOutputSpec OpaBumpLitGeomTech1Pass2 (const CVertexShaderInput input)
- {
- CVertexShaderOutputSpec output;
-
- // output position into world+view+projection space
- output.Position = mul (input.Position,WorldCameraProjection);
-
- // binormal computation based on input tangent and normal in local space
- float3 binormal = input.Normal;
-
- // Camera vertex direction
- float3 cameraDirection = ComputeVector (ObjectLocalCameraPosition,input.Position);
-
- // Light vertex direction
- float4 omniDirection1 = ComputeVectorAndLength (ObjectLocalLightPosition[0],input.Position);
-
- // half view vector computation
- float3 halfView1 = ComputeHalfViewVector (omniDirection1.xyz,cameraDirection);
- //float3 halfView1 = reflect (-omniDirection1.xyz,cameraDirection);
-
- // omni direction to texture space
- float3 omniDirectionTextureSpace = TextureSpaceTransform (omniDirection1.xyz,input.BumpTangent,input.BumpNormal,binormal);
-
- output.TextureSpaceLightVector = omniDirectionTextureSpace * 0.5f + 0.5f;
-
- // half view vector to texture space
- float3 halfView1TextureSpace = TextureSpaceTransform (halfView1,input.BumpTangent,input.BumpNormal,binormal);
-
- // half view vector 1 output to diffuse
- output.TextureSpaceLightVectorHalf = halfView1TextureSpace * 0.5f + 0.5f;
-
- // Diffuse Uv output
- output.DiffuseUv = input.DiffuseUv;
-
- // Normal Uv output
- output.NormalUv = input.DiffuseUv;
-
- output.SpecularStrength = dot (halfView1TextureSpace,binormal);
- output.SpecularStrength *= ComputeAttenuation (omniDirection1.w,LightAttenuationFarStart[0],LightAttenuationFarEnd[0],LightAttenuationDelta[0]);
-
- // fog computation
- FOG_OPTION_ON(float rFog = fog_linear(output.Position); output.Hack = float4(rFog,rFog,rFog,rFog);)
-
- return output;
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- CVertexShaderOutputTech2 OpaBumpLitGeomTech2 (const CVertexShaderInput input)
- {
- CVertexShaderOutputTech2 output;
-
- // output position into world+view+projection space
- output.Position = mul (input.Position,WorldCameraProjection);
-
- // normal computation based on input tangent and normal in local space
- float3 normal = input.Normal;
-
- float3 computedDiffuseColors[2];
-
- for (int i=0;i<2;i++)
- {
- // omnilight direction computation
- float4 omniDirection = ComputeVectorAndLength (ObjectLocalLightPosition[i],input.Position);
-
- // omnilight color computation
- float intensity = dot (omniDirection.xyz,normal);
- intensity = max(intensity,0.0f);
- intensity = min(intensity,1.0f);
- intensity *= ComputeAttenuation (omniDirection.w,LightAttenuationFarStart[i],LightAttenuationFarEnd[i],LightAttenuationDelta[i]);
- computedDiffuseColors[i].xyz = intensity * DiffuseColor[i];
-
- //computedDiffuseColors[i].xyz = dot (omniDirection.xyz,normal);
- //computedDiffuseColors[i] *= ComputeAttenuation (omniDirection.w,LightAttenuationFarStart[i],LightAttenuationFarEnd[i],LightAttenuationDelta[i]);
- //computedDiffuseColors[i] *= DiffuseColor[i];
- }
-
- // Diffuse Uv output
- output.DiffuseUv = input.DiffuseUv;
-
- // Diffuse color output
- output.DiffuseColor = computedDiffuseColors[0] + computedDiffuseColors[1];
-
- // fog computation
- FOG_OPTION_COMPUTE(output, output.Position);
-
- return output;
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- sampler DiffuseSampler = sampler_state
- {
- Texture = <DiffuseMap>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = WRAP;
- AddressV = WRAP;
- };
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- sampler NormalSampler = sampler_state
- {
- Texture = <NormalMap>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = WRAP;
- AddressV = WRAP;
- };
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- sampler SpecularSampler = sampler_state
- {
- Texture = <SpecularMap>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = WRAP;
- AddressV = WRAP;
- };
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- sampler GlossinessSampler = sampler_state
- {
- Texture = <GlossinessMap>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = CLAMP;
- AddressV = CLAMP;
- };
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- #define Pass1RenderStateBlock \
- CullMode = CW; \
- ZEnable = true; \
- ZFunc = LESSEQUAL; \
- ZWriteEnable = false; \
- AlphaBlendEnable = true; \
- SrcBlend = SRCALPHA; \
- DestBlend = INVSRCALPHA; \
- FOG_OPTION_PARAMETERS
-
- //------------------------------------------------------------------------------------------------------
-
- #define Pass2RenderStateBlock \
- CullMode = CW; \
- ZEnable = true; \
- ZFunc = LESSEQUAL; \
- ZWriteEnable = false; \
- AlphaBlendEnable = true; \
- SrcBlend = ONE; \
- DestBlend = ONE; \
- FogEnable = false
-
-
- #define Pass1RenderStateBlockTech3 \
- CullMode = CW; \
- ZEnable = true; \
- ZFunc = LESSEQUAL; \
- ZWriteEnable = false; \
- AlphaBlendEnable = false; \
- FOG_OPTION_PARAMETERS
-
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique tech1
- <
- int Priority = 1;
- int NeedSorting = 1;
- int TechniqueIndex = 0;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = INTEGRATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- Sampler[0] = <DiffuseSampler>;
- Sampler[1] = <NormalSampler>;
-
- Pass1RenderStateBlock;
-
- VertexShader = compile vs_1_1 OpaBumpLitGeomTech1Pass1();
-
- PixelShaderConstant[0] = <AmbientColor>;
- PixelShaderConstant[1] = <DiffuseColor[0]>;
- PixelShaderConstant[3] = <DiffuseColor[1]>;
-
- PixelShader =
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- tex t1 // Normal map
-
- dp3_sat r0.rgb,t1_bx2,v0_bx2 +mov_sat r0.a,t0.a // r1 = dp3 (light1 * normal)
- dp3_sat r1.rgb,t1_bx2,v1_bx2 +mov_sat r1.a,t0.a // r1 = dp3 (light1 * normal)
- mul r0.rgb,r0,c1
- mad r0.rgb,r1,c3,r0
- mul_x2_sat r0.rgb,r0,t0
- mad_sat r0.rgb,t0,c0,r0
- };
- }
-
- pass pass2
- {
- Sampler[0] = <SpecularSampler>;
- Sampler[1] = <NormalSampler>;
- Sampler[3] = <GlossinessSampler>;
-
- Pass2RenderStateBlock;
-
- VertexShader = compile vs_1_1 OpaBumpLitGeomTech1Pass2();
-
- PixelShaderConstant[2] = <SpecularColor>;
-
- PixelShader =
- asm
- {
- ps_1_1
-
- tex t0 // Specular map
- tex t1 // Normal map
- texm3x2pad t2, t1_bx2 // Light vector * normal vector
- texm3x2tex t3, t1_bx2 // Half vector * normal vector
-
- mov r0.rgb,t3 + mov r0.a,t0.a
- mul r0.rgb,r0,v0
- mul r0.rgb,r0,t0
- mul_x4 r0.rgb,r0,c2
-
- // fog hack
- mul_sat r0.rgb, r0, v1
- };
- }
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique tech2
- <
- int Priority = 1;
- int TechniqueIndex = 1;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = INTEGRATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- Sampler[0] = <DiffuseSampler>;
- Sampler[1] = <NormalSampler>;
-
- Pass1RenderStateBlock;
-
- VertexShader = compile vs_1_1 OpaBumpLitGeomTech1Pass1();
-
- PixelShaderConstant[0] = <AmbientColor>;
- PixelShaderConstant[1] = <DiffuseColor[0]>;
- PixelShaderConstant[3] = <DiffuseColor[1]>;
-
- PixelShader =
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- tex t1 // Normal map
-
- dp3_sat r0.rgb,t1_bx2,v0_bx2 +mov_sat r0.a,t0.a // r1 = dp3 (light1 * normal)
- dp3_sat r1.rgb,t1_bx2,v1_bx2 +mov_sat r1.a,t0.a // r1 = dp3 (light1 * normal)
- mul r0.rgb,r0,c1
- mad r0.rgb,r1,c3,r0
- mul_x2_sat r0.rgb,r0,t0
- mad_sat r0.rgb,t0,c0,r0
- };
- }
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique tech3
- <
- int Priority = 1;
- int TechniqueIndex = 2;
- int DeviceType = HWSHADER_ONLY;
- int LightingType = INTEGRATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- Sampler[0] = <DiffuseSampler>;
-
- //Pass1RenderStateBlock;
- Pass1RenderStateBlockTech3;
-
- VertexShader = compile vs_1_1 OpaBumpLitGeomTech2();
-
- PixelShaderConstant[0] = <AmbientColor>;
-
- PixelShader =
- asm
- {
- ps_1_1
-
- tex t0 // Diffuse map
- //tex t1 // fog hack
-
- mul_x2_sat r0.rgb,v0,t0 +mov r0.a,t0.a
- mad_sat r0.rgb,t0,c0,r0
- };
- }
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- technique techTnL_0
- <
- int Priority = 1;
- int TechniqueIndex = 0;
- int DeviceType = TNL_ONLY;
- int LightingType = INTEGRATED_LIGHTING;
- string RenderingType = "Standard";
- >
- {
- pass pass1
- {
- WorldTransform[0] = <WorldCameraProjection>;
-
- LightType[0] = POINT;
- LightAttenuation0[0] = <LightAttenuationFarStart[0]>;
- LightAttenuation1[0] = 0.0f;
- LightAttenuation2[0] = <LightAttenuationFarEnd[0]>;
- LightAmbient[0] = <AmbientColor>;
- LightDiffuse[0] = <DiffuseColor[0]>;
- LightPosition[0] = <ObjectLocalLightPosition[0]>;
- LightRange[0] = <LightAttenuationDelta[0]>;
- LightEnable[0] = true;
- LightEnable[1] = false;
- LightEnable[2] = false;
- LightEnable[3] = false;
- LightEnable[4] = false;
- LightEnable[5] = false;
- LightEnable[6] = false;
- LightEnable[7] = false;
- Lighting = true;
- MaterialAmbient = {1.0f,1.0f,1.0f,1.0f};
- MaterialDiffuse = {1.0f,1.0f,1.0f,1.0f};
- MaterialEmissive = {0.0f,0.0f,0.0f,0.0f};
- MaterialPower = 0.0f;
- MaterialSpecular = {0.0f,0.0f,0.0f,0.0f};
- DiffuseMaterialSource = COLOR1;
- AmbientMaterialSource = MATERIAL;
-
- Sampler[0] = <DiffuseSampler>;
-
- ColorArg1[0] = TEXTURE;
- ColorArg2[0] = DIFFUSE;
- ColorOp[0] = MODULATE2X;
- AlphaArg1[0] = TEXTURE;
- AlphaOp[0] = SELECTARG1;
- ColorOp[1] = DISABLE;
- AlphaOp[1] = DISABLE;
-
- Pass1RenderStateBlock;
-
- VertexShader = NULL;
-
- PixelShader = NULL;
- }
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- #include "mesh_shadow.fx"
- #include "mesh_shadow_projector.fx"
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-